<?php
namespace App\Http\Controllers;

use App\Models\ActivityProject;
use App\Models\Project;
use App\Models\ProjectDeliver;
use App\Models\RoadShowApply;
use Illuminate\Http\Request;
use \Excel;

class ProjectDeliverController extends CommonController
{

    public function getIndex()
    {
        $lists = ProjectDeliver::with('project','user','i_user')->orderBy('created_at', 'desc')->paginate(10);

        return view('projectdeliver/index')->with('lists', $lists)->with("actions", $this->actions);
    }


    public function search(Request $request)
    {
        $data = $request->input();
        $lists = ProjectDeliver::with('project','user','i_user')->orderBy('created_at', 'desc');
        if (isset($data['project_subject']) && $data['project_subject'] != '') {
            $p_ids = Project::where('subject', 'like', '%' . $data['project_subject'] . '%')->lists('id')->toArray();
            $lists->whereIn('project_id', $p_ids);
        }

        if (isset($data['is_send']) && $data['is_send'] != '') {
            $lists->where('is_send', $data['is_send']);
        }

        if (isset($data['status']) && $data['status'] != '') {
            $lists->where('status', $data['status']);
        }


        $lists = $lists->paginate(10);

        return view('projectdeliver.search')->with('lists', $lists)
            ->with('project_subject', $data['project_subject'])->with('is_send', $data['is_send'])
            ->with('status', $data['status'])->with("actions", $this->actions);
    }
}